package main

import (
	"encoding/json"
	"fmt"
	"net/http"

	"github.com/gin-contrib/gzip"
	"github.com/gin-gonic/gin"
)

var router *gin.Engine

func main() {
	router = gin.New()
	router.Use(gin.Logger())
	router.Use(gzip.Gzip(gzip.DefaultCompression))

	for _, req := range requests {
		add(req)
	}

	router.Run(fmt.Sprintf(":%d", cnf.Srv.Port))
}

func add(req *Request) {
	router.POST(req.URL, func(c *gin.Context) {
		set_header(c.Writer.Header(), req.Header)
		c.String(http.StatusOK, req.Response)
	})
}

func set_header(header http.Header, data string) error {
	m := make(map[string]string)
	err := json.Unmarshal([]byte(data), &m)
	if err != nil {
		return err
	}

	for k, v := range m {
		header.Add(k, v)
	}

	return nil
}
